package com.lili.math;

/**
 * @Auther: 李 力
 * @Date: 2024/7/31
 * @Description: 最大回文数乘积
 * @version: 1.0
 */
public class LeetCode479 {

    public int largestPalindrome(int n) {
        if (n == 1) {
            return 9;
        }
        int upper = (int) Math.pow(10, n) - 1;
        int ans = 0;
        for (int left = upper; ans == 0; left--) {
            long p = left;
            for (int x = left; x > 0; x = x / 10) {
                p = p * 10 + x % 10;
            }
            for (long x = upper; x * x >= p; x--) {
                if (p % x == 0) {
                    ans = (int) (p % 1337);
                    break;
                }
            }
        }
        return ans;
    }
}
